//
// Created by cyq on 2022/12/9.
//

#ifndef DRIVER_COMMUNICATE_H
#define DRIVER_COMMUNICATE_H

#include "main.h"

/**
  * @brief Remote switch enumeration
  */
#define RAMP_DEC (0.006f)
#define RAMP_INC (-0.015f)

#define KEY_MAX_SPEED (1.0f)

#define KEY_PRESSED_OFFSET_W(key) ((uint16_t)(key)>>0 & 0x01)
#define KEY_PRESSED_OFFSET_S(key) ((uint16_t)(key)>>1 & 0x01)
#define KEY_PRESSED_OFFSET_A(key) ((uint16_t)(key)>>2 & 0x01)
#define KEY_PRESSED_OFFSET_D(key) ((uint16_t)(key)>>3 & 0x01)
#define KEY_PRESSED_OFFSET_SHIFT(key) ((uint16_t)(key)>>4 & 0x01)
#define KEY_PRESSED_OFFSET_CTRL(key) ((uint16_t)(key)>>5 & 0x01)
#define KEY_PRESSED_OFFSET_Q(key) ((uint16_t)(key)>>6 & 0x01)
#define KEY_PRESSED_OFFSET_E(key) ((uint16_t)(key)>>7 & 0x01)
#define KEY_PRESSED_OFFSET_R(key) ((uint16_t)(key)>>8 & 0x01)
#define KEY_PRESSED_OFFSET_F(key) ((uint16_t)(key)>>9 & 0x01)
#define KEY_PRESSED_OFFSET_G(key) ((uint16_t)(key)>>10 & 0x01)
#define KEY_PRESSED_OFFSET_Z(key) ((uint16_t)(key)>>11 & 0x01)
#define KEY_PRESSED_OFFSET_X(key) ((uint16_t)(key)>>12 & 0x01)
#define KEY_PRESSED_OFFSET_C(key) ((uint16_t)(key)>>13 & 0x01)
#define KEY_PRESSED_OFFSET_V(key) ((uint16_t)(key)>>14 & 0x01)
#define KEY_PRESSED_OFFSET_B(key) ((uint16_t)(key)>>15 & 0x01)

typedef enum
{
    RC_SW_UP = 1U,
    RC_SW_MID = 3U,
    RC_SW_DOWN = 2U
} RC_Switch_Enum;

typedef struct
{
    struct
    {
        unsigned short ch0;
        unsigned short ch1;
        unsigned short ch2;
        unsigned short ch3;
        unsigned char s1;
        unsigned char s2;
    } rc;

    struct
    {
        uint16_t v;
        uint8_t keyW;
        uint8_t keyS;
        uint8_t keyA;
        uint8_t keyD;
        uint8_t keyShift;
        uint8_t keyCtrl;
        uint8_t keyQ;
        uint8_t keyE;
        uint8_t keyR;
        uint8_t keyF;
        uint8_t keyG;
        uint8_t keyZ;
        uint8_t keyX;
        uint8_t keyC;
        uint8_t keyV;
        uint8_t keyB;
    } key;
} RemoteControlStruct;

void GimbalDataUpdate(uint8_t* buffer);
void receiveJudgeHead(void);
float FourBytesToFloat (uint8_t byte1,uint8_t byte2,uint8_t byte3,uint8_t byte4);

#endif //DRIVER_COMMUNICATE_H
